﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;

namespace SinacorRules
{
    public sealed class Rule_BaseModel : BaseAddIn.Rules.BaseRuleAddIn
    {
        #region Campos

        private Type _tipoBaseModel;

        #endregion

        #region Construtor

        public Rule_BaseModel()
            : base("BaseModel", "SinacorRules.SinacorRules", typeof(Rule_BaseModel).Assembly)
        {
            _tipoBaseModel = typeof(Sinacor.Infra.UI.Common.BaseModel);
        }

        #endregion

        #region Protected Overide Methods

        protected sealed override void Check(CodeClass2 classe)
        {
			Regex r = new Regex(@"\Sinacor.UI\..+\.Model.[.+]?");
			if (r.IsMatch(classe.Namespace.Name))
            {
                if (!Common.Rotinas.CheckClassInheritance(classe, _tipoBaseModel))
                {
                    GeraProblemaAddIn(classe.StartPoint.Parent.Parent.FullName,
                                      classe.StartPoint.Line,
                                      classe.StartPoint.DisplayColumn,
                                      "BaseModelResolution",
                                      classe.Name,
                                      classe.Namespace.Name);
                }
            }
        }

        #endregion
    }
}
